package com.shioirikukuri.web.controller;

import com.shioirikukuri.common.constants.CommonConstants;
import com.shioirikukuri.common.web.Result;
import com.shioirikukuri.domain.OrderInfo;
import com.shioirikukuri.service.IOrderInfoService;
import com.shioirikukuri.web.anno.RequireLogin;
import com.shioirikukuri.web.config.UserPhone;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shioirikukuri
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderInfoController {
    @Autowired
    private IOrderInfoService orderInfoService;

    @RequestMapping("/doSeckill")
    @RequireLogin
    public Result<String> doSeckill(
            Long seckillId,
            @UserPhone String userPhone,
            @RequestHeader(name = CommonConstants.TOKEN_NAME) String token
    )
    {
        orderInfoService.doSeckill(seckillId, userPhone,token);
        return Result.success("进入抢购队列,请耐心等待结果");
    }


/*    @RequestMapping("/find")
    @RequireLogin
    public Result<OrderInfo> find(String orderNo,@UserPhone String phone) {
        //检查输入是否为空
        if(StringUtils.hasText(orderNo)){
            throw new BusinessException(CommonCodeMsg.ILLEGAL_OPERATION);
        }
        OrderInfo orderInfo = orderInfoService.find(orderNo);

        //检查是否查询到了对应信息
        if(orderInfo == null || !phone.equals(orderInfo.getPhone()))
            throw new BusinessException(CommonCodeMsg.ILLEGAL_OPERATION);
        return Result.success(orderInfo);
    }*/

    @RequestMapping("/find")
    public Result<OrderInfo> find(String orderNo) {
        return Result.success(orderInfoService.find(orderNo));
    }


}
